package component.fy.com.common_module.widget;

import android.content.Context;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.widget.RelativeLayout;

import component.fy.com.common_module.utils.MyUtil;

/**
 * 宽度为屏幕宽度的三分之一
 */
public class RatioRelativeLayoutScreen_3 extends RelativeLayout {
    private Context context;

    public RatioRelativeLayoutScreen_3(Context context) {
        super(context);
        this.context = context;
    }

    public RatioRelativeLayoutScreen_3(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }

    public RatioRelativeLayoutScreen_3(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public RatioRelativeLayoutScreen_3(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        this.context = context;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        setMeasuredDimension(getDefaultSize(0, widthMeasureSpec),
                getDefaultSize(0, heightMeasureSpec));

        int childWidthSize = MyUtil.getScreenWidth(context) / 3;
        // 高度和宽度一样
//        heightMeasureSpec = widthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
        super.onMeasure(childWidthSize, heightMeasureSpec);
    }
}
